import {defineStore} from 'pinia'
import {computed, ref} from "vue";

export const useStore = defineStore(
    'userInfoStore',
    () => {
        const userInfo = ref({})
        const token = ref<string>('')

        const getToken = computed(() => token.value)
        const getUserInfo = computed(() => userInfo.value)
        const setToken = (data: string) => token.value = data
        const setUserInfo = (data:any) => userInfo.value = data
        // 持久化配置
        return { userInfo, getUserInfo, setUserInfo,token, getToken, setToken}
    },
    // 永久化储存
    {
        persist: [
            {
                key: 'token', //存储名称
                pick: ['token'],
            },
            {
                key: 'userInfo', //存储名称
                pick: ['userInfo'],
            }
        ]
    },)